package com.ruoyi.quartz.util;

import com.ruoyi.system.domain.WxGroupSendingSchedule;
import com.ruoyi.system.domain.WxSendMsgModel;
import com.ruoyi.system.service.IWeixinService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class SendWxMsgUtil {

    private static final Logger log = LoggerFactory.getLogger(SendWxMsgUtil.class);

    private final static IWeixinService weixinService = (IWeixinService) SpringContextUtil.getBean("weixinServiceImpl");


    public static void sendWxMsg_1(String methodName){

         List<WxGroupSendingSchedule> sendingSchedules = weixinService.selectSendingScheduleDatas(methodName);

        for(WxGroupSendingSchedule schedule : sendingSchedules){
            // 微信号
            String code = schedule.getWxCode().getWxCode();
            // 模板对象
            WxSendMsgModel sendMsgModel = weixinService.getwxTemplateById(Long.valueOf(schedule.getModelId()));
            // 转化成 JsonStr 的 群发模板
            String jsonStr = weixinService.ObjectToJson(sendMsgModel);
            // 群发
            int result = weixinService.groupSending(2,code,jsonStr,"定时器群发");

            log.debug("群发是否成功(1:成功  0:失败) ==== 》》 " + result);

        }
    }
}
